package com.futonredemption.batterytest;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class FileDownloader {

	public static void downloadFile(String url) {
		getAsByteArray(url);
	}
	
	public static byte[] getAsByteArray(String url) {
		byte[] result = null;
		
		try {
			final DefaultHttpClient client = new DefaultHttpClient();
			HttpGet get = new HttpGet(url);
			HttpResponse response = client.execute(get);
			if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				HttpEntity entity = response.getEntity();
				if(entity != null) {
					result = EntityUtils.toByteArray(entity);
				}
			}
		} catch(Exception e) {}
		
		return result;
	}
}
